home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevp2up.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.7 KB  |  149 lines

  1. /* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevp2up.c,v 1.2 2000/09/19 19:00:14 lpd Exp $ */
  20. /* A "2-up" PCX device for testing page objects. */
  21. #include "gdevprn.h"
  22. #include "gdevpccm.h"
  23. #include "gxclpage.h"
  24.  
  25. extern gx_device_printer gs_pcx256_device;
  26.  
  27. /* ------ The device descriptors ------ */
  28.  
  29. /*
  30.  * Default X and Y resolution.
  31.  */
  32. #define X_DPI 72
  33. #define Y_DPI 72
  34.  
  35. /*
  36.  * Define the size of the rendering buffer.
  37.  */
  38. #define RENDER_BUFFER_SPACE 500000
  39.  
  40. /* This device only supports SVGA 8-bit color. */
  41.  
  42. private dev_proc_open_device(pcx2up_open);
  43. private dev_proc_print_page(pcx2up_print_page);
  44.  
  45. typedef struct gx_device_2up_s {
  46.     gx_device_common;
  47.     gx_prn_device_common;
  48.     bool have_odd_page;
  49.     gx_saved_page odd_page;
  50. } gx_device_2up;
  51.  
  52. private const gx_device_procs pcx2up_procs =
  53. prn_color_procs(pcx2up_open, gdev_prn_output_page, gdev_prn_close,
  54.         pc_8bit_map_rgb_color, pc_8bit_map_color_rgb);
  55. gx_device_2up gs_pcx2up_device =
  56. {prn_device_body(gx_device_2up, pcx2up_procs, "pcx2up",
  57.          DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  58.          X_DPI, Y_DPI,
  59.          0, 0, 0, 0,    /* margins */
  60.          3, 8, 6, 6, 7, 7, pcx2up_print_page)
  61. };
  62.  
  63. /* Open the device.  We reimplement this to force banding with */
  64. /* delayed rasterizing. */
  65. private int
  66. pcx2up_open(gx_device * dev)
  67. {
  68.     gx_device_printer *pdev = (gx_device_printer *) dev;
  69.     int code;
  70.     gdev_prn_space_params save_params;
  71.  
  72.     save_params = pdev->space_params;
  73.     pdev->space_params.MaxBitmap = 0;    /* force banding */
  74.     pdev->space_params.band.BandWidth =
  75.     dev->width * 2 + (int)(dev->HWResolution[0] * 2.0);
  76.     pdev->space_params.band.BandBufferSpace = RENDER_BUFFER_SPACE;
  77.     code = gdev_prn_open(dev);
  78.     pdev->space_params = save_params;
  79.     ((gx_device_2up *) dev)->have_odd_page = false;
  80.     return code;
  81. }
  82.  
  83. /* Write the page. */
  84. private int
  85. pcx2up_print_page(gx_device_printer * pdev, FILE * file)
  86. {
  87.     gx_device_2up *pdev2 = (gx_device_2up *) pdev;
  88.     const gx_device_printer *prdev_template =
  89.     (const gx_device_printer *)&gs_pcx2up_device;
  90.  
  91.     if (!pdev2->have_odd_page) {    /* This is the odd page, just save it. */
  92.     pdev2->have_odd_page = true;
  93.     return gdev_prn_save_page(pdev, &pdev2->odd_page, 1);
  94.     } else {            /* This is the even page, do 2-up output. */
  95.     gx_saved_page even_page;
  96.     gx_placed_page pages[2];
  97.     int x_offset = (int)(pdev->HWResolution[0] * 0.5);
  98.     int y_offset = (int)(pdev->HWResolution[1] * 0.5);
  99.     int code = gdev_prn_save_page(pdev, &even_page, 1);
  100.     int prdev_size = prdev_template->params_size;
  101.     gx_device_printer *prdev;
  102.  
  103. #define rdev ((gx_device *)prdev)
  104.  
  105.     if (code < 0)
  106.         return code;
  107.     /* Create the placed page list. */
  108.     pages[0].page = &pdev2->odd_page;
  109.     pages[0].offset.x = x_offset;
  110.     pages[0].offset.y = 0 /*y_offset */ ;
  111.     pages[1].page = &even_page;
  112.     pages[1].offset.x = pdev->width + x_offset * 3;
  113.     pages[1].offset.y = 0 /*y_offset */ ;
  114.     /* Create and open a device for rendering. */
  115.     prdev = (gx_device_printer *)
  116.         gs_alloc_bytes(pdev->memory, prdev_size,
  117.                "pcx2up_print_page(device)");
  118.     if (prdev == 0)
  119.         return_error(gs_error_VMerror);
  120.     memcpy(prdev, prdev_template, prdev_size);
  121.     gx_device_fill_in_procs(rdev);
  122.     set_dev_proc(prdev, open_device,
  123.              dev_proc(&gs_pcx256_device, open_device));
  124.     prdev->printer_procs.print_page =
  125.         gs_pcx256_device.printer_procs.print_page;
  126.     prdev->space_params.band =
  127.         pages[0].page->info.band_params;    /* either one will do */
  128.     prdev->space_params.MaxBitmap = 0;
  129.     prdev->space_params.BufferSpace =
  130.         prdev->space_params.band.BandBufferSpace;
  131.     prdev->width = prdev->space_params.band.BandWidth;
  132.     prdev->OpenOutputFile = false;
  133.     code = (*dev_proc(rdev, open_device)) (rdev);
  134.     if (code < 0)
  135.         return code;
  136.     rdev->is_open = true;
  137.     prdev->file = pdev->file;
  138.     /* Render the pages. */
  139.     code = gdev_prn_render_pages(prdev, pages, 2);
  140.     /* Clean up. */
  141.     if (pdev->file != 0)
  142.         prdev->file = 0;    /* don't close it */
  143.     gs_closedevice(rdev);
  144.     pdev2->have_odd_page = false;
  145.     return code;
  146. #undef rdev
  147.     }
  148. }
  149.